package script;

import javax.script.ScriptEngineFactory;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import java.util.ArrayList;
import java.util.List;

/**
 * .
 *
 * @author sunhao(sunhao.java@gmail.com)
 * @version 1.0 2016/12/9 下午7:35
 */
public class Scripting {
    public static void main(String[] args) throws ScriptException, NoSuchFieldException, IllegalAccessException {
        ScriptEngineManager manager = new ScriptEngineManager();
        List<ScriptEngineFactory> factories = manager.getEngineFactories();
        List<String> names = new ArrayList<>();
        for (ScriptEngineFactory factory : factories) {
            names.addAll(factory.getNames());
        }

        for (String name : names) {
            System.out.println(name);
        }

        System.out.println("=============");

        String rubyCode1 = "2+19";
        System.out.println(manager.getEngineByName("ruby").eval(rubyCode1));
    }
}
